package domain;


import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import android.util.Log;


public class TCP
{
	public String strTCP="TCP";
	
	public boolean TCPSender(String strDataToSend)
	{
		Socket sock = null; 
			 try
	  		  {
				 
		   		/*
		   		   	
		   		 sock = new Socket("190.18.128.130",5123);
		   		sock.setSoTimeout(5000);
		   		*/					   							   		
		   		SocketAddress sockaddr = new InetSocketAddress("190.18.128.130",5123);
		   		sock = new Socket();
		   		sock.connect(sockaddr, 5000);
	  		  }catch(Exception ex)
	  		  {
	  			Log.e(strTCP,"[TCP] NO SE CONECTO EL SOCKET: "+ex);			//DEBUG
	  			return false;
	  		  }
		 	try
		 	{

			   		Log.i(strTCP,"[TCP] CONEXION SOCKET CREADA ");			//DEBUG   		
			   		Log.i(strTCP,"[TCP] SOCKET IP: "+String.valueOf(sock.getLocalPort()));			//DEBUG
			   		Log.i(strTCP,"[TCP] SOCKET PORT: "+String.valueOf(sock.getLocalPort()));			//DEBUG
			   		Log.i(strTCP,"[TCP] SOCKET IS CONNECTED?: "+String.valueOf(sock.isConnected()));			//DEBUG
			   		//Log.i(TAG,"[onLocationChanged] SOCKET ADDRESS Local: "+String.valueOf(sock.getLocalSocketAddress()));			//DEBUG	   		
			   		Log.i(strTCP,"[TCP] SOCKET ADDRESS Remote: "+String.valueOf(sock.getRemoteSocketAddress()));			//DEBUG
			   		
			   		  String test = strDataToSend;
			   		  
			   		  Log.i(strTCP,"[TCP] Stream enviado: "+test);					//DEBUG
			   		  
			   		  sock.getOutputStream().write(test.getBytes());
			   		  
			   		  sock.getOutputStream().flush();
			   		  sock.close();  			   		

			}catch(Exception ex)
			{
				Log.e(strTCP,"[TCP] Error de envio: "+ex);			//DEBUG
	  			
			}
		 	return true;
	}

}
